﻿using System;
using Highchart.Core;
using Highchart.Core.Options;
using Highchart.Core.PlotOptions;
using Highchart.Core.ScriptServices;

namespace Highchart.UI
{
    public class AreaChart : Chart, IChart
    {

        protected override void OnPreRender(EventArgs e)
        {
            Render();
        }

        public PlotOptionsArea PlotOptions
        {
            get
            {
                object o = ViewState["PlotOptionsArea"];
                if (o == null)
                    return new PlotOptionsArea();
                return (PlotOptionsArea)o;
            }
            set { ViewState["PlotOptionsArea"] = value; }
        }

        public void Render()
        {
            var chartOptions = new ChartOptions
                                   {
                                       ClientId = ClientID,
                                       Lang = Lang,
                                       Appearance = Appearance,
                                       Colors = Colors,
                                       RenderType = RenderType,
                                       Legend = Legend,
                                       Exporting = Exporting,
                                       ShowCredits = ShowCredits,
                                       Title = Title,
                                       SubTitle = SubTitle,
                                       Tooltip = new ToolTip(ToolTip),
                                       YAxis = YAxis,
                                       XAxis = XAxis,
                                       Series = Series,
                                       Theme = Theme,
                                       AjaxDataSource = AjaxDataSource,
                                       PlotOptions = PlotOptions
                                   };

            var areaChartScript = ScriptBuilder.BuildAreaChart(chartOptions);

            System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "chart_" + ClientID, areaChartScript, true);

        }

    }
}
